'--------------------------------------------------------'
' Description:
'   This script intend for print net name to pins
'--------------------------------------------------------'
Option Explicit
Dim docObj
' Add any type libraries to be used. 
Scripting.AddTypeLibrary("MGCPCB.ExpeditionPCBApplication")
Dim app,doc,docMenuBarObj
set app= application
set doc = app.activedocument
Set docMenuBarObj = app.Gui.CommandBars("Document Menu Bar")

main
sub main()
	GetUserLicence(doc)
	'msgbox doc.name
	'doc.currentunit=2
	UserEditCotrol(doc)
	
end sub

sub UserEditCotrol(docObj)
    docObj.currentunit=2
	application.gui.activemode = 1'route
    docObj.EditorControl.Grid (0,0)=3 'epcbGridComponentPrimary
    docObj.EditorControl.Grid (1,0)=3 'epcbGridComponentSecondary 	
	docObj.EditorControl.Grid (2,0)=1.5 ' epcbGridDrawing 
	application.gui.activemode = 0'place
	docObj.EditorControl.Grid (4,0)=0
    docObj.EditorControl.Grid (6,0)=0

    docObj.EditorControl.PartsRefdesHorzOrientation (1)=  0
	docObj.EditorControl.PartsRefdesHorzOrientation (0)=  1
	docObj.EditorControl.PartsRefdesVertOrientation(1)=  0
	docObj.EditorControl.PartsRefdesVertOrientation(0)=  0

	docObj.EditorControl.AutoSave(0)=10
	docObj.EditorControl.AutoSave(1)=10
	docObj.EditorControl.Routes(1)=false
    
end sub

Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

sub GetUserLicence(docObj)

	If ValidateServer(docObj) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
	
end sub	

